/**
* @file 抢购
* @author 张超
* @created 2023/6/30 08:00
* @updated 2023/6/30 18:00
*/
<template>
	<view class="shop" :style="{ background:'url('+rankingBgData+')',backgroundSize:'100% 100% !important'}">
		<view class="title">抢购专区</view>
		<view class="title-des">
			<text>前210次抢购的中奖订单不发货</text>
		</view>
		<view class="fiexd" @click="ptquan">我的抢购:{{overcounts}}</view>

		<scroll-view scroll-y="true" @scrolltolower="lower" class="scroll-Y">
			<ul>
				<li v-for="(item,index) in rushList" :key="index" @click="detail(item)">
					<view class="left">
						<image :src="item.image_text"></image>
						<text>{{item.need_total}}人团</text>
					</view>
					<view class="right">
						<text>{{item.title}}</text>
						<!-- each_price等于0显示 -->
						<view class="fas" v-if="item.each_price==0.00"
							:style="{ background:'url('+asd+')',backgroundSize:'100% 100% !important'}">
							<view>
								{{item.group_price | xiaos}}健康值
								<text style="text-decoration:line-through">{{item.price | xiaos}}健康值</text>
							</view>
							<view class="">去抢购</view>
						</view>
						<!-- each_price不等于0显示 -->
						<view v-else class="jinbiw">
							<view>
								<text class="money coor" style="">{{item.each_price | xiaos}}</text>企业产权+
								<text class="money "
									style="color:red;font-size:40rpx">{{item.each_price | xiaos}}</text>金币
							</view>
							<view style="font-size:22rpx;">可得三件</view>
						</view>
					</view>
				</li>
			</ul>
		</scroll-view>
		<u-mask :show="show" @click="show = false">
			<view class="cany-pop" @click="">
				<image src="/static/shop/cany.png" style="width:100%;height:100%"></image>
			</view>
		</u-mask>
		<!-- <uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" confirmText="去支付" :title="titlew" @confirm="dialogInputConfirm">
				<radio-group v-model="type" @change="handleOptionChange">
					<radio value="wechat" checked="true">微信</radio>
					<radio value="alipay" style="margin-left: 20rpx;">支付宝</radio>
				</radio-group>
			</uni-popup-dialog>
		</uni-popup> -->

	</view>
</template>

<script>
	import {
		goodList,
		priceCommit,
		submit
	} from '@/network/api.js'
	import {
		getUserinfo,
	} from '@/network/loginAndMy.js'
	export default {
		data() {
			return {
				show: false,
				page: 1,
				asd: '../../../static/shop/asd.png',
				rankingBgData: '../../../static/shop/group.png',
				rushList: [],
				user_info: {},
				// 健康值
				health: '',
				// 金币
				money: '',
				// 当前产权/金币,0.00已入金
				each_price: '',
				// 产权
				value: '',
				// 提醒标题
				titlew: '',
				// 支付方式
				type: 'wechat',
				overcounts:0,
			}
		},
		onLoad() {
			this.getUserinfo()
			this.rushRe()
		},
		onShow() {
			this.getUserinfo()
			this.rushRe()
		},
		filters: {
			// 过滤小数点后面数据
			xiaos(num) {
				return Math.trunc(num)
			},
		},
		methods: {
			// 选择支付方式
			handleOptionChange(event) {
				const newVal = event.mp.detail;
				this.type = newVal.value
				// 在这里执行你希望触发的操作
			},
			// 获取用户信息
			getUserinfo() {
				getUserinfo().then(res => {
					if (res.code == 1) {
						this.user_info = res.data
						this.health = this.user_info.health
						this.money = this.user_info.money
						this.overcounts = this.user_info.overcounts
					}
				})
			},
			// 获取抢购列表数据
			rushRe() {
				let data = {
					page: this.page,
					pageSize: 10
				}
				goodList(data).then(res => {
					if (this.page == 1) {
						this.rushList = res.data.data
					} else {
						this.rushList = [...this.rushList, ...res.data.data]
					}
					this.getUserinfo()
				})
			},
			lower: function(e) {
				this.page++
				this.rushRe()
			},
			// 充值
			dialogInputConfirm() {
				let data = {
					score: 10,
					money: 10.00,
					typeid: 1
				}
				// console.log(data,'触发')
				priceCommit(data).then(res => {
					if (res.code == 1) {
						let data1 = {
							out_trade_no: res.data.out_trade_no,
							title: res.data.title,
							amount: res.data.amount,
							type: this.type,
							notifyurl: '/addons/epay/api/notifyx?type=' + this.type
						}
						console.log(data1, '支付2')
						uni.request({
							url: 'https://huijiank.com/addons/epay/api/submit', //仅为示例，并非真实接口地址。
							data: data1,
							success: (ress) => {
								if (this.type == 'alipay') {
									uni.requestPayment({
										provider: this.type,
										orderInfo: ress,
										success: function(res) {
											uni.showToast({
												title: '支付失败',
												icon: 'none',
												duration: 3000,
											})
										},
										fail: function(err) {
											uni.showToast({
												title: '支付失败',
												icon: 'none',
												duration: 3000,
											});
										}
									})
								} else {
									uni.requestPayment({
										provider: 'wxpay',
										orderInfo: ress,
										success: function(res) {
											uni.showToast({
												title: '支付失败',
												icon: 'none',
												duration: 3000,
											})
										},
										fail: function(err) {
											uni.showToast({
												title: '支付失败',
												icon: 'none',
												duration: 3000,
											});
										}
									})
								}
							}
						})
					}
				})
			},
			// 跳转到充值
			goChonz(item) {
				if (Number(this.money) < Number(this.each_price)) {
					// if (false) {
					// 如果个人金币小于商品金币,去充值
					let number = this.each_price - this.money
					this.titlew = '需匹配' + number + '的金币'
					uni.showToast({
						title: this.titlew,
						icon: "none",
						duration: 2000,
					});
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/subpackage/my/recharge'
						})
					}, 1000)
				} else if (Number(this.health) < Number(this.each_price)) {
					// } else if (false) {
					// 如果个人产权小于商品产权,去充值
					this.value = this.each_price - this.health
					this.titlew = '需先购买价值' + this.value + '的企业产权'
					uni.showToast({
						title: this.titlew,
						icon: "none",
						duration: 2000,
					});
				} else {
					let data = {
						type: 2,
						number: item.stock_sales,
						typee: 1,
						market: item
					}
					uni.navigateTo({
						url: '/pages/subpackage/shop/qconfig?data=' + JSON.stringify(data)
					})
				}
			},
			// 跳转到详情页
			detail(item) {
				//未入金
				if (item.each_price != '0.00') {
					// if(true){
					this.each_price = item.each_price
					// this.goChonz(item)
					uni.showToast({
						title: '请先消费',
						icon: "none",
						duration: 2000,
					});
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/subpackage/shop/seckill'
						})
					}, 1000)
				} else {
					//已入金
					uni.navigateTo({
						url: '/pages/subpackage/shop/shopDetail?id=' + item.id
					})
				}
			},
			// 跳转到我的拼团
			ptquan(id) {
				uni.navigateTo({
					url: '/pages/subpackage/shop/wopt'
				})
			}
		}
	}
</script>

<style lang="scss">
	.shop {
		width: 100%;
		padding: 50rpx 0;

		.cany-pop {
			position: fixed;
			top: 20%;
			width: 70vw;
			height: 500rpx;
			margin-left: 15vw;
		}

		.title {
			text-align: center;
			font-style: italic;
			font-size: 70rpx;
			color: #fff;
			font-family: YouSheBiaoTiHei, YouSheBiaoTiHei-Regular;
		}

		.title-des {
			text-align: center;
			font-size: 50rpx;
			color: #fff;
		}

		.fiexd {
			position: fixed;
			top: 80rpx;
			right: 0;
			max-width: 230rpx;
			height: 50rpx;
			text-align: center;
			line-height: 48rpx;
			color: #864417;
			border-top-left-radius: 30rpx;
			border-bottom-left-radius: 30rpx;
			background-color: #FFD490;
			border: 1rpx solid #fff;
		}

		.fiexd:active {
			background-color: #edc899;
		}

		.scroll-Y {
			.uni-scroll-view {
				.uni-scroll-view {
					.uni-scroll-view-content {
						>ul {
							margin-top: 30rpx;
							margin-bottom: 30rpx;
							height: calc(100vh - 310rpx);

							>li {
								display: flex;
								justify-content: space-between;
								height: 220rpx;
								margin: 20rpx 30rpx;
								padding: 20rpx;
								box-sizing: border-box;
								border-radius: 10rpx;
								background-color: #fff;

								.left {
									position: relative;
									width: 180rpx;
									height: 180rpx;

									>image {
										width: 100%;
										height: 100%;
										border: 1rpx solid #fff;
									}

									>text {
										position: absolute;
										text-align: center;
										background-color: #fff;
										top: 0;
										width: 100rpx;
										font-size: 26rpx;
										border-bottom-right-radius: 10rpx;
										background-color: #edc899;
									}
								}

								.right {
									display: flex;
									flex-direction: column;
									width: 448rpx;

									>text:nth-child(1) {
										display: flex;
										font-family: PingFang SC, PingFang SC-Medium;
										color: #595757;
									}

									.jinbiw {
										display: flex;
										align-items: center;
										justify-content: space-between;
										margin-top: auto;

										>view:nth-child(1) {
											display: flex;
											align-items: center;
											font-size: 20rpx;
											color: #FD3C0C;

											.money {
												display: flex;
												font-size: 40rpx
											}
										}
									}

									.fas {
										display: flex;
										align-items: center;
										justify-content: space-between;
										height: 66rpx;
										padding: 0 30rpx;
										margin-top: auto;

										>view:nth-child(1) {
											font-size: 36rpx;
											color: #fff;
											margin-left: -20rpx;
											font-family: PingFang SC, PingFang SC-Bold;

											>text {
												font-size: 24rpx;
											}
										}

										>view:nth-child(2) {
											font-size: 30rpx;
											color: #864417;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
</style>